<template>
    <StElUpload
            ref="stelupload"
            class="single-image-uploader"
            :show-file-list="false"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload">
        <img v-if="imageUrl" :src="imageUrl" class="single-image">
        <i v-else class="el-icon-plus single-image-uploader-icon"></i>
    </StElUpload>
</template>

<script>
    export default {
        name: 'StElUploadSingleImage',
        props:{
            value: String
        },
        data() {
            return {
                imageUrl: this.value,
            };
        },
        methods: {
            handleAvatarSuccess(res, file) {
                this.imageUrl = res.url
                this.$emit('input',this.imageUrl)
                this.$emit('data',res)
            },
            beforeAvatarUpload(file) {

            }
        },
        watch:{
            value(val, oldVal) {
                this.imageUrl = val
            }
        }
    }
</script>
<style scoped>
    .single-image-uploader {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }
    .single-image-uploader:hover {
        border-color: #409EFF;
    }
    .single-image-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 178px;
        height: 178px;
        line-height: 178px;
        text-align: center;
    }
    .single-image {
        width: 178px;
        height: 178px;
        display: block;
    }
</style>
